<?php


define('ERR_PARAM', -1);
define('ERR_SYSTEM', -2);
define('ERR_TOKEN', -3);
define('ERR_SIGN', -4);


function failure($code = -10, $hint = '未知错误')
{
	switch ($code)
	{
		case ERR_PARAM:
		{
			$hint  = "参数错误！";
		
			break;
		}
		case ERR_SYSTEM:
		{
			$hint  = "系统错误！";

			break;
		}
		case ERR_TOKEN:
		{
			$hint  = "token无效！";

			break;
		}
		case ERR_SIGN:
		{
			$hint  = "签名错误！";

			break;
		}
		default:
		{
			break;
		}
	}

	echo json_encode(['code' => (int)$code, 'hint' => $hint]);
	
	exit();
}

function success($result = [])
{
	$code  = 0;
	$hint  = '成功';

	if (isset($result['code']))
	{
		$code  = $result['code'];
	}

	if (isset($result['hint']))
	{
		$hint  = $result['hint'];
	}

	if (isset($result['data']))
	{
		echo json_encode(['code' => (int)$code, 'hint' => $hint, 'data' => $result['data']]);
	}
	else
	{
		echo json_encode(['code' => (int)$code, 'hint' => $hint]);
	}

	exit();
}
